package com.fufan.mtsaas.modules.newtech.xjsyearaudit.controller;


import com.fufan.mtsaas.modules.common.bo.request.DataRequestT;
import com.fufan.mtsaas.modules.common.bo.request.ResultPack;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditApproveRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditDeleteRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditIdRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditQueryByIdRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditQueryRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.request.XjsYearAuditSaveRequest;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.response.XjsYearAuditResponse;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.bo.response.XjsYearAuditTotal;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.model.XjsYearAudit;
import com.fufan.mtsaas.modules.newtech.xjsyearaudit.service.XjsYearAuditSvc;
import com.fufan.mtsaas.util.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * 新技术-年审模块相关接口
 * </p>
 *
 * @author Liby
 * @since 2024-12-16
 */
@Api(tags = "新技术-年审模块相关接口", description = "XjsYearAudit对象接口")
@RestController
@RequestMapping("/MTSaas/xjsYearAudit")
@Slf4j
public class XjsYearAuditCtrl {

    @Autowired
    private XjsYearAuditSvc targetService;

    @ApiOperation(value = "我申请的年审", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doMyAuditApplication")
    public Result<XjsYearAuditResponse> doMyAuditApplication(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doMyAuditApplication(mapData, requestPojo);
    }

    @ApiOperation(value = "我的年审草稿", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doMyDraftQuery")
    public Result<XjsYearAuditResponse> doMyDraftQuery(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doMyDraftQuery(mapData, requestPojo);
    }

    @ApiOperation(value = "已完成项目年审", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doCompletedProjectAudit")
    public Result<XjsYearAuditResponse> doCompletedProjectAudit(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doCompletedProjectAudit(mapData, requestPojo);
    }

    @ApiOperation(value = "待确认的阶段评审", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doPendingStageReviewConfirmation")
    public Result<XjsYearAuditResponse> doPendingStageReviewConfirmation(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doPendingStageReviewConfirmation(mapData, requestPojo);
    }

    @ApiOperation(value = "已确认的阶段评审", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doConfirmedStageReview")
    public Result<XjsYearAuditResponse> doConfirmedStageReview(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doConfirmedStageReview(mapData, requestPojo);
    }

    /**
     * 审批
     */
    @ApiOperation(value = "审批", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value = "/doApprove", method = RequestMethod.PUT)
    public Result<Boolean> doApprove(@RequestBody DataRequestT<XjsYearAuditApproveRequest> dataRequest) {
        log.debug("doApprove parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsYearAuditApproveRequest map = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doApprove(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 删除数据
     */
    @ApiOperation(value = "删除数据", httpMethod = "DELETE", produces = "application/json")
    @RequestMapping(value = "/doDelete", method = RequestMethod.DELETE)
    public Result doDelete(@RequestBody DataRequestT<XjsYearAuditDeleteRequest> dataRequest) {
        log.debug("doDelete parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsYearAuditDeleteRequest map = dataRequest.getData().getParam();

        return resultPack.doResultPack(targetService.doDelete(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 表单数据、详情
     */
    @ApiOperation(value = "表单数据、详情", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doDetail", method = RequestMethod.POST)
    public Result<XjsYearAuditResponse> doDetail(@RequestBody DataRequestT<XjsYearAuditQueryByIdRequest> dataRequest) {
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsYearAuditQueryByIdRequest map = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doDetail(map, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    /**
     * 新增、编辑、暂存申报
     */
    @ApiOperation(value = "新增、编辑、暂存申报", httpMethod = "POST", produces = "application/json", response = Result.class)
    @RequestMapping(value = "/doSave", method = RequestMethod.POST)
    public Result<XjsYearAudit> doSaveMap(@RequestBody @Valid DataRequestT<XjsYearAuditSaveRequest> dataRequest) {
        log.debug("doSave parameter: {}", dataRequest);

        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doSave(dataRequest.getData().getParam(), requestPojo);
    }

    /**
     * 提交申报
     */
    @ApiOperation(value = "提交申报，先调用doSave方法", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value = "/doUpdate", method = RequestMethod.PUT)
    public Result<XjsYearAudit> doUpdateMap(@RequestBody @ApiIgnore @Valid DataRequestT<XjsYearAuditIdRequest> dataRequest) {
        log.debug("doUpdate parameter: {}", dataRequest);

        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        XjsYearAuditIdRequest mapData = dataRequest.getData().getParam();
        return resultPack.doResultPack(targetService.doUpdate(mapData, requestPojo), requestPojo.getIntfId(), requestPojo.getAppKey());
    }

    @ApiOperation(value = "查询分析-年审列表", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doYearAuditApplication")
    public Result<XjsYearAuditResponse> doYearAuditApplication(@RequestBody DataRequestT<XjsYearAuditQueryRequest> dataRequest) {
        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doYearAuditApplication(mapData, requestPojo);
    }

    @ApiOperation(value = "查询分析-年审列表统计", httpMethod = "POST", produces = "application/json")
    @PostMapping(value = "/doYearAuditTotal")
    public Result<XjsYearAuditTotal> doYearAuditTotal() {
//        XjsYearAuditQueryRequest mapData = dataRequest.getData().getParam();
//        RequestPojo requestPojo = ParamUtil.doChange();
        return targetService.doYearAuditTotal();
    }
}
